#!/bin/bash
source /etc/profile

table=$1
keys='';values='';count=0;update=''
echo $table
for i in $(awk '{print $1","$2","$3}' /home/marvin/daily_job/update/table/$table)
do
line=($(echo $i|awk -F',' '{print $1,$2,$3}'))
#echo ${line[2]}
count=$(expr $count + 1)
echo count:$count
key=${line[0]};is_num=${line[1]};is_unique=${line[2]}
keys="$keys,$key";values="$values,\$$count"
update="$update,$key=\$$count"
done

keys=${keys#,};values=${values#,};update=${update#,}
echo keys:$keys
echo values:$values
#for i in $(seq 1 $count)
#do
#done

#echo "awk -F '\t' '{print INSERT into test.res_oil($keys) VALUES($values)  on duplicate key update $update;}'"

sql="select $keys from $table limit 10"
echo $sql
cd /home/marvin/hive-1.1.0-cdh5.6.0
#bin/hive -e "$sql" |awk '{print "INSERT into test.res_oil("$keys") VALUES('$values')  on duplicate key update '$update';' }"
sql=$(bin/hive -f res_oil.hql -d dt=$dt|awk -F '\t' -f res_oil.awk)
mysql -uroot -proot -hhadoop3 -e "sql"
